package com.iot08.admin.shiro;

import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * shiro配置类
 *
 * @version 1.0
 * @author:rock
 * @time:2020年8月10日 下午2:57:38
 */
@Configuration
public class ShiroConfig {

    @Bean
    public ShiroFilterFactoryBean shiroFilterFactoryBean(
            @Qualifier("securityManager") DefaultWebSecurityManager securityManager) {
        ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
        bean.setSecurityManager(securityManager);
        return bean;
    }

    @Bean("securityManager")
    public DefaultWebSecurityManager getSecurityManage(@Qualifier("accountRealm") ShiroRealm shiroRealm) {
        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
        securityManager.setRealm(shiroRealm);
        securityManager.setSessionMode(DefaultWebSecurityManager.NATIVE_SESSION_MODE);
        return securityManager;
    }

    @Bean("accountRealm")
    public ShiroRealm getAccountRealm() {
        return new ShiroRealm();
    }

}
